import 'package:flutter/cupertino.dart';
import 'package:mahjong/entity/mahjong/MahjongInfoEntity.dart';
import 'package:mahjong/notify/CurrentUserInfo.dart';
import 'package:mahjong/notify/LeftUserInfo.dart';
import 'package:mahjong/notify/RightUserInfo.dart';
import 'package:mahjong/notify/TopUserInfo.dart';
import 'package:provider/provider.dart';

import 'CustomNavigatorObserver.dart';

/**
 * 有可能游戏中 会存在上一局的  数据  
 * 在进入房间  或者    创建房间之前要做数据清理
 */

class ProviderClean {
  static void cleanMahjongRoom() {
    Provider.of<MahjongInfoEntity>(
            CustomNavigatorObserver.getInstance().navigator.context,
            listen: false)
        .clean();
  }

  static void cleanMahjongUser() {
    BuildContext context = CustomNavigatorObserver.getContext();
    Provider.of<CurrentUserInfo>(context, listen: false).cleanUserInfo();
    Provider.of<TopUserInfo>(context, listen: false).cleanUserInfo();
    Provider.of<RightUserInfo>(context, listen: false).cleanUserInfo();
    Provider.of<LeftUserInfo>(context, listen: false).cleanUserInfo();
  }

  static void cleanAll() {
    // 清理麻将 房间信息
    cleanMahjongRoom();
    // 清理 麻将 玩家信息
    cleanMahjongUser();
  }
}
